package com.winchain.chainbill.bill.biz.discount.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.framework.utils.SysDateUtil;
import com.shell.governor.modules.message.keyword.SysDctApplyKeyword;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.transfer.vo.BillSplitEvent;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class BillSplitDctMsgSubscriber extends OnErrorNotImplementedSubscriber<BillSplitEvent<CbDct>> {
	public void onApplicationEvent(BillSplitEvent<CbDct> t) {
		CbDct cbDct = null;
		List<Bill<CbDct>> children = (List<Bill<CbDct>>) t.getChildren();
		for (Bill<CbDct> bill : children) {
			if (bill.getSource() != null) {
				cbDct = (CbDct) bill.getSource();
			}
		}
		String template = "MT01611";
		SysDctApplyKeyword keyWord = new SysDctApplyKeyword();
		keyWord.setDctAmt(String.valueOf(cbDct.getDctAmt()));

		String dctDate = SysDateUtil.parseDate(cbDct.getDctDate(), "yyyyMMdd", "yyyy-MM-dd");
		keyWord.setDctDate(dctDate);
		keyWord.setContactorName(CommonDataUtil.getUserName());

		String senderId = CommonDataUtil.getUserId();
		MessageSender.sendMessageByTmpl(senderId, template, keyWord, cbDct.getSellerId());
	}
}
